package com.gdssoft.framework.dao.system.impl;
/*
 *  捷达世软件(深圳)有限公司
 *  Copyright (C) 2008-2010 ShenZhen JieDaShi Software Limited Company.
*/
import java.util.List;

import com.gdssoft.core.dao.impl.BaseDaoImpl;
import com.gdssoft.core.web.paging.PagingBean;
import com.gdssoft.framework.dao.system.DepartmentDao;
import com.gdssoft.framework.model.system.Department;

@SuppressWarnings("unchecked")
public class DepartmentDaoImpl extends BaseDaoImpl<Department> implements DepartmentDao {

	public DepartmentDaoImpl() {
		super(Department.class);
	}

	@Override
	public List<Department> findByParentId(Long parentId, PagingBean pb) {
		final String hql = "from Department d where d.parentId=?";
		Object[] params ={parentId};
		if (null != pb) 
			return findByHql(hql, params, pb);
		else 
			return findByHql(hql, params);
	}
	
	@Override
	public List<Department> findByParentId(Long parentId,Integer depLevel, PagingBean pb) {
		final String hql = "from Department d where d.parentId=?"+(depLevel!=null?" and d.depLevel="+depLevel:"");
		Object[] params ={parentId};
		if (null != pb) 
			return findByHql(hql, params, pb);
		else 
			return findByHql(hql, params);
	}

	@Override
	public List<Department> findByPath(String path, PagingBean pb) {
		String hql="from Department vo where vo.path like ?";
		String[] param={path+"%"};
		if (null != pb) 
			return findByHql(hql, param, pb);
		else 
			return findByHql(hql,param);
	}

	@Override
	public List<Department> getByOfficeId(Long officeId, PagingBean pb) {
		final String hql ="from Department d where d.tpOrgOfficeInfo.id=?";
		Object[] params = {officeId};
		if(null != pb)
			return findByHql(hql, params, pb);
		else
			return findByHql(hql,params);
	}
	
	@Override
	public List<Department> getByCompanyId(Long companyId, PagingBean pb) {
		final String hql ="from Department d where d.tpOrgCompanyInfo.id=?";
		Object[] params = {companyId};
		if(null != pb)
			return findByHql(hql, params, pb);
		else
			return findByHql(hql,params);
	}

	@Override
	public List<Department> findByPath(String path, int level) {
		String hql="from Department vo where vo.depLevel=? and vo.path like ?";
		List<Department> list = findByHql(hql,new Object[]{level,path+"%"});
		return list;
	}

}
